package com.example.wan1;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.wan1.base.BaseMvpActivity;
import com.example.wan1.base.InjectPresenter;
import com.example.wan1.data.ResponseList;
import com.example.wan1.flowable.ThirdActivity;
import com.example.wan1.look.LookContract;
import com.example.wan1.look.LookPresenter;
import com.example.wan1.model.ArticleBean;
import com.example.wan1.second.ArticleAdapter;

import javax.inject.Inject;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import dagger.android.AndroidInjection;

/***
 * 需要改造成dagger2的模式
 * 1.创建application，继承DaggerApplication
 * 2.建立一个app级别的module
 * 3.创建一个app级别的component
 * 4.
 *
 * 问题：view和presenter没有绑定
 */
public class SecondActivity extends BaseMvpActivity implements LookContract.View {

    @BindView(R.id.recycler_view)
    RecyclerView mRecyclerView;

    @InjectPresenter
    LookPresenter mPresenter;

    @Inject
    ArticleAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        AndroidInjection.inject(this);//注入
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_second);
        ButterKnife.bind(this);

        mPresenter.getData();

//        mAdapter = new ArticleAdapter(R.layout.item_art, null);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setAdapter(mAdapter);

        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intent = new Intent(SecondActivity.this, ThirdActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public void onSuccess(ResponseList<ArticleBean> bean) {
        Log.i("zxd", "onSuccess: " + bean.getDatas().size());
        mAdapter.setNewData(bean.getDatas());
    }

    @Override
    public void onFailure(String msg) {

    }

    @Override
    public Context getContext() {
        return this;
    }
}
